<?php

ob_start();
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}
include 'operations/connection.php';


if (isset($_REQUEST['agree'])) {
    $idmanager = $_REQUEST['idmanager'];
    $idgroup = $_REQUEST['idgroup'];
    $sql = "DELETE FROM list_reference WHERE id_group='$idgroup' AND id_manager='$idmanager' AND id_status !=1;";
    mysql_query($sql);


    $listreference = $_SESSION['listreference'];
    $i = $_SESSION['slreference'];
    for ($j = 0; $j < $i; $j++) {

        $sql = "INSERT INTO list_reference (id_employee, id_manager, id_group, id_status) VALUES ('$listreference[$j]', '$idmanager', '$idgroup', '4')";
        mysql_query($sql);
    }
}

mysql_close($con);
session_unregister('listreference');
session_unregister('slreference');
$id = $_REQUEST['id'];
$type = $_REQUEST['type'];
header("Location: received.php?id=$id&type=$type");
ob_flush();
?>